﻿using System.IO;
using Telerik.Reporting.Processing;

namespace EmailReporting
{
    public class Invoicing
    {
        // Author: Otto Neff | webapps-in-action.com 
        public MemoryStream CreatePdfInvoice(Data.Invoice data)
        {
            ReportProcessor reportProcessor = new ReportProcessor();
            Reports.Invoice i = new Reports.Invoice();
            i.DataSource = data;
            RenderingResult result = reportProcessor.RenderReport("PDF", i, null);
            return new MemoryStream(result.DocumentBytes);

            // For Debuging - instead of return stream save it to file

            using (FileStream file = new FileStream("temp.pdf", FileMode.Create, FileAccess.Write))
            {
                MemoryStream ms = new MemoryStream(result.DocumentBytes);
                ms.WriteTo(file);
            }
            System.Diagnostics.Process.Start("temp.pdf");
        }
    }
}